/**
 * @UiLabel.cpp
 * Copyright 2013 (C) FatalEror / Dean Bahari
 * 
 * UiPack is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * See LICENSE file in main folder for more information.
 */

#include "UiCommon.hpp"
#include "UiApp.hpp"
#include "UiBase.hpp"
#include "UiLabel.hpp"
#include "UiResource.hpp"

UiLabel::UiLabel(UiBase *parent, const wchar_t *text, int width, int height, int x, int y)
	: UiBase(text, parent)
{
	mBkColor = parent->getBkColor();

	this->setSize(width, height);
	this->setPosition(x, y);
	ShowWindow(this->getHandle(), SW_SHOWDEFAULT);
	UpdateWindow(this->getHandle());
}

LRESULT CALLBACK UiLabel::handleCustomProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_ERASEBKGND:
		return 1;
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hDC = BeginPaint(this->getHandle(), &ps);

		Gdiplus::Graphics graph(hDC);
		Gdiplus::GraphicsPath path;
		Gdiplus::StringFormat sf;
		sf.SetLineAlignment(Gdiplus::StringAlignmentCenter);
		graph.FillRectangle(UiApp::getResource()->getBrush(this->getBkColor()), 0, 0, this->getWidth(), this->getHeight());
		path.AddString(this->getName(), -1, UiApp::getResource()->getFont(), Gdiplus::FontStyleRegular, 11, Gdiplus::PointF(0.0f, this->getHeight() / 2.0f), &sf);
		graph.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
		graph.DrawPath(UiApp::getResource()->getPen(UiResource::UI_PEN_TEXT), &path);
		graph.FillPath(UiApp::getResource()->getBrush(UiResource::UI_BRUSH_TEXT), &path);
		graph.SetSmoothingMode(Gdiplus::SmoothingModeNone);

		EndPaint(this->getHandle(), &ps);
	} break;
	default:
		return DefWindowProc(this->getHandle(), msg, wParam, lParam);
	}
	return 0;
}